
namespace gen {

	template <class FunctorT>
	template <typename IteratorT>
	class find_expr<FunctorT>::find_expr_initializator 
	{
	private:
		IteratorT m_reference;
		FunctorT m_expr;
		
	public:
		find_expr_initializator( FunctorT const& expr, IteratorT const& reference )
		: m_expr(expr), m_reference(reference)
		{}

		bool operator()(IteratorT const& i)
		{
			return m_expr(m_reference, i);
		}
	};

	template <class FunctorT>
	template <typename GeneratorT, typename InfoT>
	void 
	find_expr<FunctorT>::compute(GeneratorT const& g, InfoT & f) const
	{
		typedef typename InfoT::iterator_t		iterator_t;
		typedef find_expr_initializator<iterator_t> initializator_t;

		initializator_t init(expr, f.current());
		domain<iterator_t> tmp(f.domain().first(), f.domain().last(), init);
		domain_t saveDomain = f.swapDomain(tmp);

		for (iterator_t i = f.domain().firstPositive(); i<f.domain().lastPositive(); ++i)
		{
			if (f.domain().points()[i])
			{
				g.generate(f);
			}
		}
		f.swapDomain(saveDomain);

	}

	template <class T>
	inline find_expr<T>
	find_g(const T & f)
    {
        return find_expr<T>(f);
    }

}
